package com.ssrs.dev.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.ssrs.dev.model.Device;
import com.ssrs.dev.model.DeviceVO1;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 教室设备管理：设备表 Mapper 接口
 * </p>
 *
 * @author 拾年之璐
 * @since 2021-05-19
 */
public interface DeviceMapper extends BaseMapper<Device> {

//    @Select("SELECT\n" +
//            "\td.id AS id,\n" +
//            "\td.device_no AS deviceNo,\n" +
//            "\td.device_name AS deviceName,\n" +
//            "\td.device_classroom AS deviceClassroom,\n" +
//            "\tc.room_building AS roomBuilding,\n" +
//            "\tc.room_number AS roomNumber \n" +
//            "FROM\n" +
//            "\tcxh_device d,\n" +
//            "\tcxh_classroom c \n" +
//            "WHERE\n" +
//            "\td.device_classroom = c.id")
//    List<DeviceVO> getDeviceVOList();

    /**
     * 设备信息统计
     *
     * @return 列表
     */
    @Select("SELECT\n" +
            "\td.device_no AS deviceNo,\n" +
            "\td.device_name AS deviceName,\n" +
            "\tCOUNT(*) AS deviceSum,\n" +
            "\tSUM( CASE WHEN d.device_classroom <> 'NULL' THEN 1 ELSE 0 END ) AS deviceUsed,\n" +
            "\tSUM( CASE WHEN d.device_classroom <> 'NULL' THEN 0 ELSE 1 END ) AS deviceFree \n" +
            "FROM\n" +
            "\ttable_device d \n" +
            "GROUP BY\n" +
            "\td.device_no \n" +
            "ORDER BY\n" +
            "\tdeviceSum DESC \n" +
            "\tLIMIT 5")
    List<DeviceVO1> getStats01();

}
